package com.cn.yang.servlet.mainPage;

import com.alibaba.fastjson.JSONObject;
import com.cn.yang.model.mainPage.HeadAndFootModel;
import com.cn.yang.service.MainPageService;
import com.cn.yang.service.impl.MainPageServiceImpl;
import com.cn.yang.util.UpLoad;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/mainPage/updateHeadFoot")
public class UpdateHeadFootServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        UpLoad upLoad = new UpLoad();
        String string = upLoad.imgUpload(req);
        System.out.printf("LJJIIII"+string);
        String a = (String) req.getSession().getAttribute("photo");
        String aa[] = string.split("@@",-1);
        if (aa[2].toString().equals("undefined")){
            aa[2]=a;
        }
        HeadAndFootModel model = new HeadAndFootModel();
        model.setTitle(aa[0]);
        model.setEnglishtitle(aa[1]);
        model.setPhoto(aa[2]);
        model.setFoothref(aa[3]);
        model.setFootwords(aa[4]);

        MainPageService service = new MainPageServiceImpl();
        int result = service.updataHeadFoot(model);
        JSONObject js = new JSONObject();
        js.put("result",result);
        resp.getWriter().println(result);
    }
}
